home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sources.misc
- subject: v08i099: checkfiles for comp.sources.misc
- from: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
- Reply-To: mpb@osf.org (Paul Blackburn)
-
- Posting-number: Volume 8, Issue 99
- Submitted-by: mpb@osf.org (Paul Blackburn)
- Archive-name: checkfiles
-
- Here is 'checkfiles', a script for keeping track of changes to
- files. System administrators may find this useful to have unwanted
- or unexpected changes to files reported to them.
-
- Paul Blackburn, "live free or die..."
- Open Software Foundation, European Development, Munich, West Germany
- mail: mpb@osf.de Internet: mpb@mn.osf.org uucp: ..uunet!mcvax!unido!osfmuc!mpb
- ------------------------------cut here----------coupe ici-----------
- #! /bin/sh
- # This is a shell archive, meaning:
- # 1. Remove everything above the #! /bin/sh line.
- # 2. Save the resulting text in a file.
- # 3. Execute the file with /bin/sh (not csh) to create the files:
- # checkfiles
- # This archive created: Tue Oct 31 16:54:39 1989
- # By: Paul Blackburn (Open Software Foundation, European Development, Munich)
- export PATH; PATH=/bin:$PATH
- if test ! -d 'checkfiles'
- then
- echo shar: creating directory "'checkfiles'"
- mkdir 'checkfiles'
- fi
- echo shar: entering directory "'checkfiles'"
- cd 'checkfiles'
- echo shar: extracting "'Makefile'" '(85 characters)'
- if test -f 'Makefile'
- then
- echo shar: will not over-write existing file "'Makefile'"
- else
- sed 's/^X//' << \SHAR_EOF > 'Makefile'
- X# Makefile to build ftype
- X
- Xftype: ftype.c Makefile
- X $(CC) $(CFLAGS) -o ftype ftype.c
- SHAR_EOF
- fi # end of overwriting check
- echo shar: extracting "'README'" '(3430 characters)'
- if test -f 'README'
- then
- echo shar: will not over-write existing file "'README'"
- else
- sed 's/^X//' << \SHAR_EOF > 'README'
- XIntroduction:
- X
- Xcheckfiles is a shellscript to check for changes to a set of
- Xfiles and report differences by mail.
- X
- XProblem:
- X
- XI want to know when certain files have been changed but I don't want to
- Xhave to check them out myself because it takes me too long.
- X
- XAs systems administrator I have to know if /bin/login changes
- Xespecially if I did not change it!
- X
- XSolution:
- X
- XHave a program do the checking for me and mail me the changes.
- XUse a list of files to be checked and keep 'original' copies :-)
- Xto check current versions against.
- X
- XThe tools I use to do this are:
- X
- Xresetfiles - Update the reference copy of files
- Xcheckfiles - find out if any changes, mail the results
- Xftype - Determine is file is a binary (not diff'able)
- X
- XEnvironment:
- X
- XThese Bourne shellscripts have been tested under ULTRIX and
- Xshould (let me know if otherwise) run under most UNIXes.
- XThe tools are Bourne shellscripts and 'make' is also used.
- X
- XHow to install:
- X
- Xa) run a 'make' to compile ftype.c.
- X
- Xb) Edit the file 'list' to reflect the files you need to check.
- X I haven't used a huge list yet, it seems a good idea to keep the
- X list short.
- X
- Xc) Define where the reference copies are to be held. Edit both
- X checkfiles and resetfiles and change the value of BASE to
- X the current directory.
- X
- Xd) To avoid problems of checkfiles running on the wrong host
- X edit both checkfiles and resetfiles and set MASTER to the hostname
- X it should only run on. There was a problem using checkfiles in a
- X configuration with many workstations sharing the same (remote)
- X filestore.
- X
- Xe) Define who should receive mail about any changes to the files.
- X Edit 'checkfiles' and change NOTIFY to your requirement.
- X
- Xf) Run a 'resetfiles' to create your reference copy of file(s) from 'list'.
- X These are stored under $BASE/originals.
- X
- Xg) Run a 'checkfiles', you should get:
- X
- X 0 files changed
- X
- Xh) Set up a crontab entry to run checkfiles as often as you wish.
- X Here is an example entry for crontab to run each hour:
- X
- X0 * * * * /usr/local/bin/checkfiles >> /usr/lib/cronlog
- X
- X I use the excellent 'watcher' program [1] that was distributed
- X over USENET to invoke 'checkfiles'.
- X
- X Here is an example entry for a Watcherfile:
- X
- X(/usr/local/bin/checkfiles) { 'file changes' }
- X 1 count%d 2 file%s 3 changed%s:
- X count 0 0.
- X
- XUsing checkfiles:
- X
- XWhen checkfiles reports some change(s) to a file you have to decide
- Xwhether the change is OK or not. If you are happy with the change then
- Xrun a 'resetfiles' to update the reference copy otherwise you will
- Xcontinue to receive notification about the change every time you
- Xrun checkfiles.
- X
- Xcheckfiles reports on changes to binary files by giving checksum information
- Xand changes to non-binary files by providing 'diff' output.
- X
- XDo be careful about the location and access rights to the 'originals'
- Xdirectory. If an intruder found this (s)he would of course change
- Xboth the current file and the one in 'originals'.
- X
- XReferences:
- X
- X[1] watcher by Kenneth Ingham,
- X University of New Mexico Computing Center,
- X 2701 Campus NE,
- X Alburquerque, NM, 87131
- X ingham@charon.unm.edu or ucbvax!unmvax!charon!ingham
- X
- XCaveat: not guaranteed for anything but fun to run
- X
- XAuthor:
- X
- XPaul Blackburn, "live free or die..."
- XOpen Software Foundation, Stefan-George-Ring 29, D-8000 Munich 81, W Germany
- XMail: mpb@osf.de, mpb@mn.osf.org, ..uunet!mcvax!unido!osfmuc!mpb
- XTel: +49-89-93092-123 Fax: +49-89-93092-104
- SHAR_EOF
- fi # end of overwriting check
- echo shar: extracting "'checkfiles'" '(1964 characters)'
- if test -f 'checkfiles'
- then
- echo shar: will not over-write existing file "'checkfiles'"
- else
- sed 's/^X//' << \SHAR_EOF > 'checkfiles'
- X#!/bin/sh5
- X# NAME checkfiles
- X# AUTHOR Paul Blackburn, OSF, Munich
- X# DATE Sat Oct 21 11:52:05 MET 1989
- X# PURPOSE Compares originals with current, reports diffs
- X
- XPATH=/usr/ucb:/bin:/usr/bin
- Xexport PATH
- XIFS="
- X"
- Xexport IFS
- X
- XBASE=/users/mpb/masters
- XNOTIFY=mpb
- XMASTER=osfmuc
- X
- XLIST=${BASE}/list
- XODIR=originals
- XORIG=${BASE}/${ODIR}
- XMAKE=${BASE}/Makefile.re
- XTMP1=/usr/tmp/check1.$$
- XTMP2=/usr/tmp/check2.$$
- XTMP3=/usr/tmp/check3.$$
- X
- XCMD=`basename ${0}`
- X
- Xif [ "${MASTER}" != "`uuname -l`" ]
- Xthen
- X echo "Error: ${CMD} should be executed on ${MASTER}" >&2
- X exit 1
- Xfi
- X
- Xif [ -d "${BASE}" ]
- Xthen
- X cd $BASE
- Xelse
- X echo "${CMD}: unable to cd to ${BASE}" >&2
- X exit 1
- Xfi
- X
- X# Create a Makefile from LIST
- X
- Xif [ ! -z "${DEBUG}" ]
- Xthen
- X echo "Creating list of files"
- Xfi
- X
- Xgrep -v "^#" <$LIST \
- X| sed -e "/^$/d" \
- X| cut -c2- >${TMP1}
- X
- Xif [ ! -z "${DEBUG}" ]
- Xthen
- X echo "Checking current versus original"
- Xfi
- X
- Xwhile FILE=`line`
- Xdo
- X CFILE=/${FILE}
- X OFILE=${ORIG}/${FILE}
- X cmp ${OFILE} ${CFILE} 2>&1 >/dev/null
- X if [ $? = 1 ]
- X then
- X if [ ! -z "${DEBUG}" ]
- X then
- X echo "/${FILE} changed"
- X fi
- X
- X echo ${FILE} >>${TMP3}
- X fi
- Xdone <${TMP1}
- X
- Xif [ -s ${TMP3} ]
- Xthen
- X for FILE in `cat ${TMP3}`
- X do
- X ls -ldg ${ODIR}/${FILE} >${TMP2}
- X ls -ldg /${FILE} >>${TMP2}
- X X=`${BASE}/ftype ${ORIG}/${FILE}`
- X if [ -z "${X}" ]
- X then
- X echo "\n<original\n>current" >>${TMP2}
- X diff ${ORIG}/${FILE} /${FILE} >>${TMP2}
- X else
- X echo "\nChecksums:" >>${TMP2}
- X sum ${ODIR}/${FILE} /${FILE} >>${TMP2}
- X fi
- X echo "\nlogins when change was noticed " >>${TMP2}
- X who >>${TMP2}
- X mail -s "/${FILE} changed" ${NOTIFY} <${TMP2}
- X done
- X COUNT=`wc -l ${TMP3} | cut -c1-8`
- X COUNT=`echo ${COUNT}`
- Xelse
- X COUNT=0
- Xfi
- X
- Xrm -f ${TMP1} ${TMP2} ${TMP3}
- X
- X#
- X# This last bit is for use with a system monitor program
- X# It reports the status to the parent
- X#
- X
- Xecho "${COUNT} file\c"
- Xif [ ${COUNT} != 1 ]
- Xthen
- X echo "s\c"
- Xfi
- Xecho " changed\c"
- X
- Xif [ ${COUNT} -gt 0 ]
- Xthen
- X echo " (details mailed to ${NOTIFY})"
- Xelse
- X echo
- Xfi
- Xexit
- SHAR_EOF
- chmod +x 'checkfiles'
- fi # end of overwriting check
- echo shar: extracting "'ftype.c'" '(2172 characters)'
- if test -f 'ftype.c'
- then
- echo shar: will not over-write existing file "'ftype.c'"
- else
- sed 's/^X//' << \SHAR_EOF > 'ftype.c'
- X#include <stdio.h>
- X
- X/* Atype.c find numbers of different types of characters in
- X* a file...Rich Kulawiec, 8/2/82 revised 10/86
- X* Note that characters 200-377 octal are mapped down.
- X*
- X* Modified by Paul Blackburn (mpb@mn.osf.org) to determine
- X* if file is 'binary' (i.e. executable, directory) so that
- X* diff could not be used on it.
- X*/
- X
- Xchar *maptable[16][8] = {
- X "nul", "soh", "stx", "etx", "eot", "enq", "ack", "bel",
- X "bs ", "ht ", "nl ", "vt ", "np ", "cr ", "so ", "si ",
- X "dle", "dc1", "dc2", "dc3", "dc4", "nak", "syn", "etb",
- X "can", "em ", "sub", "esc", "fs ", "gs ", "rs ", "us ",
- X "sp ", " ! ", " \" "," # ", " $ ", " % ", " & ", " ' ",
- X " ( ", " ) ", " * ", " + ", " , ", " - ", " . ", " / ",
- X " 0 ", " 1 ", " 2 ", " 3 ", " 4 ", " 5 ", " 6 ", " 7 ",
- X " 8 ", " 9 ", " : ", " ; ", " < ", " = ", " > ", " ? ",
- X " @ ", " A ", " B ", " C ", " D ", " E ", " F ", " G ",
- X " H ", " I ", " J ", " K ", " L ", " M ", " N ", " O ",
- X " P ", " Q ", " R ", " S ", " T ", " U ", " V ", " W ",
- X " X ", " Y ", " Z ", " [ ", " \\ ", " ] ", " ^ ", " _ ",
- X " ` ", " a ", " b ", " c ", " d ", " e ", " f ", " g ",
- X " h ", " i ", " j ", " k ", " l ", " m ", " n ", " o ",
- X " p ", " q ", " r ", " s ", " t ", " u ", " v ", " w ",
- X " x ", " y ", " z ", " { ", " | ", " } ", " ~ ", "del"
- X } ;
- X
- Xint count[8][16];
- X
- XFILE *fp;
- XFILE *fopen();
- X
- Xmain(argc, argv)
- Xint argc;
- Xchar *argv[];
- X{
- X int c,i,j,k,nprint,nread;
- X
- X/* only need to read the first 128 bytes */
- X
- X nread=0;
- X if(argc == 1)
- X {
- X fp = stdin;
- X while(((c = getc(fp)) != EOF) && (nread < 128))
- X {
- X count[ ((c&0177) % 8) ][ ((c&0177) / 8) ]++;
- X nread++;
- X }
- X }
- X else
- X {
- X for ( i = 1; i < argc; i++)
- X {
- X if( (fp=fopen(argv[i],"r")) == NULL)
- X {
- X (void) fprintf(stderr,"atype: can't open %s\n",argv[i]);
- X continue;
- X }
- X while(((c = getc(fp)) != EOF) && (nread < 128))
- X {
- X count[ ((c&0177) % 8) ][ ((c&0177) / 8) ]++;
- X nread++;
- X }
- X (void) fclose(fp);
- X }
- X }
- X
- X nprint=0;
- X for(k=0; k<4; k++)
- X {
- X for(j=0; j<8; j++)
- X nprint+=count[j][k];
- X }
- X nprint-=count[1][1]; /* discount tabs */
- X nprint-=count[2][1]; /* discount newlines */
- X if (nprint > 0)
- X {
- X (void) printf("binary\n");
- X }
- X}
- SHAR_EOF
- fi # end of overwriting check
- echo shar: extracting "'list'" '(700 characters)'
- if test -f 'list'
- then
- echo shar: will not over-write existing file "'list'"
- else
- sed 's/^X//' << \SHAR_EOF > 'list'
- X# This file contains a list of files that are checked for changes (mpb21Oct89)
- X# (this is for an ULTRIX system, edit for other flavours)
- X
- X/.rhosts
- X/etc/exports
- X/etc/fstab
- X/etc/group
- X/etc/hosts
- X/etc/hosts.equiv
- X/etc/passwd
- X/etc/rc
- X/etc/rc.local
- X/usr/bin/login
- X/usr/bin/passwd
- X/usr/bin/su
- X/usr/lib/aliases
- X/usr/lib/crontab
- X/usr/lib/mail.aliases
- X/usr/lib/sendmail.cf
- X/usr/local/lib/syswatch
- X/usr/local/lib/watcher/Daemons
- X/usr/local/lib/watcher/OSFHosts
- X/usr/local/lib/watcher/Watcherfile
- X/usr/var/yp/src/group
- X/usr/var/yp/src/hosts
- X/usr/var/yp/src/netgroup
- X/usr/var/yp/src/networks
- X/usr/var/yp/src/passwd
- X/usr/var/yp/src/protocols
- X/usr/var/yp/src/rpc
- X/usr/var/yp/src/services
- X/usr/var/yp/src/ypservers
- SHAR_EOF
- fi # end of overwriting check
- echo shar: extracting "'resetfiles'" '(2009 characters)'
- if test -f 'resetfiles'
- then
- echo shar: will not over-write existing file "'resetfiles'"
- else
- sed 's/^X//' << \SHAR_EOF > 'resetfiles'
- X#!/bin/sh5
- X# NAME resetfiles
- X# AUTHOR Paul Blackburn, OSF, Munich
- X# DATE Sat Oct 21 11:52:05 MET 1989
- X# PURPOSE Re-creates the reference copies for checkfiles to check against
- X
- XPATH=/usr/ucb:/bin:/usr/bin
- Xexport PATH
- XIFS="
- X"
- Xexport IFS
- X
- XBASE=/users/mpb/masters
- XMASTER=osfmuc
- X
- XLIST=${BASE}/list
- XORIG=${BASE}/originals
- XMAKE=${BASE}/Makefile.re
- XTEMP=/usr/tmp/reset.$$
- XCMD=`basename ${0}`
- X
- Xif [ "${MASTER}" != "`uuname -l`" ]
- Xthen
- X echo "Error: ${CMD} should be executed on ${MASTER}" >&2
- X exit 1
- Xfi
- X
- Xif [ -d "${BASE}" ]
- Xthen
- X cd $BASE
- Xelse
- X echo "${CMD}: unable to cd to ${BASE}" >&2
- X exit 1
- Xfi
- X
- XTMP1=/usr/tmp/tmp1.$$
- XTMP2=/usr/tmp/tmp2.$$
- XTMP3=/usr/tmp/tmp3.$$
- X
- Xif [ ! -z "${DEBUG}" ]
- Xthen
- X echo "Extracting from list"
- Xfi
- X
- Xcd ${BASE}
- Xgrep -v "^#" <$LIST | sed -e "/^$/d" | cut -c2- | sort >${TMP1}
- X
- Xif [ ! -z "${DEBUG}" ]
- Xthen
- X echo "Creating list from originals"
- Xfi
- X
- Xcd ${ORIG}
- Xfind . -type f -print | cut -c3- | sort >${TMP2}
- X
- Xif [ ! -z "${DEBUG}" ]
- Xthen
- X echo "Comparing two lists"
- Xfi
- X
- Xcomm -13 ${TMP1} ${TMP2} >${TMP3}
- X
- Xif [ -s ${TMP3} ]
- Xthen
- X
- X if [ ! -z "${DEBUG}" ]
- X then
- X echo "Removing unwanted files from originals"
- X fi
- X
- X <${TMP3} xargs -t rm -f
- Xfi
- X
- Xif [ ! -z "${DEBUG}" ]
- Xthen
- X echo "Removing temporary files"
- Xfi
- X
- Xrm ${TMP1} ${TMP2} ${TMP3}
- X
- X# Create a Makefile from LIST
- X
- Xif [ ! -z "${DEBUG}" ]
- Xthen
- X echo "Creating Makefile"
- Xfi
- X
- Xcat <<eeooff >$MAKE
- X# Makefile to rebuild original file copies
- X# generated by `uuname -l`:$USER on `date`
- X
- XORIG=${ORIG}
- X
- Xall: \\
- Xeeooff
- X
- Xif [ ! -z "${DEBUG}" ]
- Xthen
- X echo "Creating all dependencies"
- Xfi
- X
- Xgrep -v "^#" <$LIST \
- X| sed -e "/^$/d" \
- X| cut -c2- >${TEMP}
- X
- Xsed -e "s/.$/&\\\\/" <${TEMP}\
- X| sed -e "s,^.,\ \$(ORIG)/&," >>$MAKE
- X
- Xecho "\t${BASE}/README" >> $MAKE
- X
- Xwhile FILE=`line`
- Xdo
- X cat <<eeooff >>$MAKE
- X
- X\$(ORIG)/${FILE}: /$FILE
- X cd /; echo ${FILE} | cpio -pdmuva \$(ORIG)
- Xeeooff
- Xdone <${TEMP}
- Xrm ${TEMP}
- X
- Xif [ ! -z "${DEBUG}" ]
- Xthen
- X echo "Executing Makefile"
- Xfi
- X
- Xmake -f ${MAKE}
- X
- Xif [ ! -z "${DEBUG}" ]
- Xthen
- X echo "Deleting Makefile"
- Xfi
- X
- Xrm ${MAKE}
- Xexit
- SHAR_EOF
- chmod +x 'resetfiles'
- fi # end of overwriting check
- if test ! -d 'originals'
- then
- echo shar: creating directory "'originals'"
- mkdir 'originals'
- fi
- echo shar: entering directory "'originals'"
- cd 'originals'
- echo shar: done with directory "'originals'"
- cd ..
- echo shar: done with directory "'checkfiles'"
- cd ..
- # End of shell archive
- exit 0
-
-